define(["require",
	'config/appregister',
	"business/services/constant",
	"business/blogpost/service/blogHttp",
	"business/services/personCenterComp",
	"business/services/detailNavComp",
	"jquery", "domReady",
	"business/services/filter",
	"business/home/services/filterService",
	"business/services/commentComp",
	
], function(require, app, constant, httpServices) {
	app.controller('othersBlogInfoCtrl', function($scope, $http, $state, $stateParams,$rootScope,$sce) {
		if(!angular.isUndefined($stateParams.blogId,$stateParams.userId,$stateParams.type)) {
			$scope.blogids = $stateParams.blogId;
			$scope.userId = $stateParams.userId;
			$scope.type = $stateParams.type;
		}
		var blogid = $scope.blogids;
		var type = 0;
		//跳编辑博文
		$scope.modify = function() {
			$state.go("blogmod",{blogid:blogid});
		};
		
		//跳转他的工程界
		$scope.goToEng = function(a){
			$state.go(a);
		}
		
		//有谁看过
		function getmark() {
			var req = {
				type:'GET',
				uri:'getMark',
				data:{
					fkId:$scope.blogids,
					type:'',
					count:10
				}
			};
			httpServices.getmarkService(req).success(function(data){
				if(!data)return;
				if(data.code==0) {
					console.log(data);
					$scope.$apply(function(){
						if(data.data.length<1) {
							$("#nullli").show();
						}else{
							$("#nullli").hide();
							$scope.mark = data.data;
						}						
					});
				}else {
					alert(data.msg)
				}
			}).error(function(){
				alert("请求mark失败");
			});
		};
		//痕迹跳转
		$scope.otherpage = function(id) {
//			$state.go("hasMainPage")
		}
		
		
		//跳上一篇下一篇
		$scope.jump = function(fpres) {
			if(!fpres)return;
			blogid = fpres;
			getblog();
			getxq();
			getmark();
		};
		getblog();
		getxq();
		getmark();
		
		//收藏
		$scope.getupdate = function() {
			var req = {
				type:'POST',
				uri:'update',
				data:{
					fkId:$scope.blogids,
					type:0
				}
			};
			httpServices.updateService(req).success(function(data){
				if(!data)return;
				console.log(data);
				if(data.code == 0) {
					$(".sc").html("已收藏").css({
						"background":"url(them/img/collectioned.png) 0px 2px no-repeat"
					});
				} else if(data.code == 112) {
					$(".sc").html("收藏").css({
						"background":"url(them/img/aiai.png) 0px 2px no-repeat"
					});
				};
			}).error(function(){
				alert("收藏请求失败");
			});
		};
		//跳转其他博文
		$scope.gotoother = function(theid){
			if(!theid)return;
			blogid = theid;
			getblog();
			getxq();
			getmark();
		};
		//查其他博文
		function getblog() {
			var req = {
				type:'GET',
				uri:'getOtherBlogByUserId',
				data:{
					pageNo:1,
					pageSize:10,
					all:false,
					type:0+","+2,
					blogId:$scope.blogids,
					userId:$scope.userId
				}
			};
			httpServices.getmarkService(req).success(function(data){
				if(!data)return;
				if(data.code==0) {
					$scope.other = data.data.list;
				}else {
					alert(data.msg);
				}
			}).error(function(){
				console.log("查其它博文失败");
			});
		};

		//查详情
		function getxq() {

			var req = {
				type:"GET",
				uri:"getInfoByUserId",
				data:{
					blogId:$scope.blogids,
					type:$scope.type,
					userId: $scope.userId
				}
			};
			httpServices.getblogHttpService(req).success(function(data){
				if(!data)return;
				$scope.$apply(function(){	
					if(data.code==0) {
							$sce.trustAsHtml(data.data.blog.introduction);
							$scope.title = data.data.blog.title;
							$scope.time = data.data.blog.createTime;
							$scope.nickname = data.data.blog.nickname;
							$scope.content = data.data.blog.introduction;
							$scope.fenlei = data.data.blog.dcList[0].detailCategory.dcName;
							$scope.comment = data.data.blog.commentCount;
							$scope.hot = data.data.blog.browseCount;
							$scope.labels = data.data.blog.labelList;
							$scope.flag = data.data.blog.flag;
							$scope.userId = data.data.blog.userId;
							
							if($scope.flag==true){
								$(".sc").html("已收藏").css({
									"background":"url(them/img/collectioned.png) 0px 2px no-repeat"
								});							
							}else {
								$(".sc").html("收藏").css({
									"background":"url(them/img/aiai.png) 0px 2px no-repeat"
								});
							};
							if(data.data.fpre) {
								$scope.fpre = data.data.fpre.title;
								$scope.fpres = data.data.fpre.blogId;
							} else {
								$scope.fpre = "暂无数据";
							}
							if(data.data.fnext) {
								$scope.next = data.data.fnext.title;
								$scope.fnexts = data.data.fnext.blogId;
							} else {
								$scope.next = "暂无数据";
							}							
					}else {
						alert(data.msg);
					}
				});
			}).error(function(){
				alert("详情请求失败");
			});
			
			//评论配置
			$scope.commentConf = {
            	isshowStar: false,
            	conf: {
                	id: $scope.blogids,
                	type: $scope.type
            	}
       		};

		}

	});
});